<template>
  <van-overlay :show="show">
    <div
      class="wrapper polaroid"
      @click.stop
    >
      <span class="prize-title">恭喜获得</span>
      <div class="polaroid-box">
        <div class="polaroid-detail">
          <img
            :src="lightGif"
            alt=""
            class="polaroid-gif"
          >
        </div>
        <div class="detail-box">
          <img
            v-if="info&&info.poster"
            :src="info.poster"
            alt=""
            class="bind-box-img"
          >
          <span>{{name}}</span>
        </div>
      </div>
      <van-button
        plain
        hairline
        type="primary"
        round
        @click.stop="acceptBlindbox"
      >立即收下</van-button>
      <!--  -->
      <!-- 0是现金券1是商品 品类目，0是实物，1是虚拟 -->
      <span class="convert" @click="onConvertMoneyClick" v-if="info.type===1">不想要，折换现金券</span>
    </div>
    <!-- <div
      class="wrapper money"
      @click.stop
      v-if="prizeInfo.type==0"
    >
      <div class="money-box">
        <span class="prize-title">嗨，送你一张抽盒券</span>
        <div class="box">
          <img
            :src="blindBox"
            alt=""
          >
          <div class="detail">
            <div class="left">
              <span>￥</span>
              <span>{{prizeInfo.price/100}}</span>
            </div>
            <div class="right">
              <span></span>
              <span>过期时间：</span>
            </div>
          </div>
        </div>
        <van-button
          plain
          hairline
          type="primary"
          round
          @click.stop="acceptBlindbox"
        >立即收下</van-button>
      </div>
      <van-icon name="close" @click="hideOverlay"/>
    </div> -->
  </van-overlay>
</template>

<script>
import { Button, Overlay } from "vant";
export default {
  name: "AccepBlindBox",
  components: {
    [Button.name]: Button,
    [Overlay.name]: Overlay,
  },
  props: {
    prizeInfo: {
      type: Object,
      default: () => {},
    },
  },
  watch: {
    prizeInfo: {
      deep: true,
      handler: function (val) {
        this.info = val;
        if (val.name.length && val.name.length > 10) {
          name = val.name.substring(0, 10) + "...";
        }
        if (val.name.length && val.name.length <= 10) {
          name = val.name;
        }
        this.name = name;
      },
    },
  },
  data() {
    return {
      lightGif:
        "http://alivod.sdxgxx.cn/image/default/2C61890CED224B698D0691740C09AEEF-6-2.png",
      show: false,
      info: {},
      blindBox: require("../common/imgs/blind-box.png"),
      name: "",
    };
  },
  created() {
    this.info = this.prizeInfo;
    let name = "";
    if (this.prizeInfo.name&&this.prizeInfo.name.length && this.prizeInfo.name.length > 10) {
      name = this.prizeInfo.name.substring(0, 10) + "...";
    }
    if (this.prizeInfo.name&&this.prizeInfo.name.length && this.prizeInfo.name.length <= 10) {
      name = this.prizeInfo.name;
    }
    this.name = name;
  },
  methods: {
    showOverlay() {
      this.show = true;
    },
    hideOverlay() {
      this.show = false;
    },
    // 收下盲盒
    acceptBlindbox() {
      this.$emit("acceptBlindbox",this.prizeInfo);
    },
    //  点击折换现金券
    onConvertMoneyClick(){
      this.$emit("convertMoney");
    }
  },
};
</script>

<style scoped lang="less">
.wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;

  .prize-title {
    font-size: 54px;
    color: #fde78f;
    line-height: 68px;
  }

  .bind-box-img {
    width: 339px;
    height: 339px;
    margin: 0 0 100px;
  }

  .van-button--plain.van-button--primary {
    width: 360px;
    height: 120px;
    background: #3f87f0;
    border-radius: 60px;
    border: none;
    font-size: 40px;
    font-weight: 500;
    color: #ffffff;
  }
}
.polaroid {
  .detail-box {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    width: 460px;
    height: 420px;
    padding-bottom: 65px;
    box-sizing: border-box;
    background: linear-gradient(180deg, #dbe9fc 0%, #fcefde 100%);
    box-shadow: 0px 0px 3px 8px rgba(179, 201, 233, 0.75);
    border-radius: 28px;
    position: relative;
    margin-top: 75px;
    margin-bottom: 40px;

    span {
      font-size: 34px;
      font-weight: 500;
      color: #222222;
      line-height: 48px;
    }

    .money-img {
      position: absolute;
      top: -70px;
      left: 0;
      right: 0;
      margin: auto;
      width: 296px;
      height: 302px;
    }
  }
}

.wrapper.polaroid {
  .polaroid-box {
    width: 420px;
    height: 420px;
    position: relative;
    margin-top: 150px;
    margin-bottom: 30px;

    .polaroid-detail {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 420px;
      height: 420px;
      background: linear-gradient(180deg, #dbe9fc 0%, #fcefde 100%);
      box-shadow: 0px 0px 3px 8px rgba(179, 201, 233, 0.75);
      border-radius: 28px;
      overflow: hidden;

      .polaroid-gif {
        width: 500px;
        height: 500px;
      }
    }

    .detail-box {
      position: absolute;
      top: -80px;
      left: 0;
      width: 100%;
      height: 100%;
      background: none;
      box-shadow: none;
    }
  }
}
.wrapper.money {
  .money-box {
    width: 596px;
    height: 578px;
    padding: 34px 30px 68px 32px;
    box-sizing: border-box;
    background: #ffffff;
    border-radius: 40px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
  }
  .prize-title {
    font-size: 32px;
    font-weight: 500;
    color: #222222;
  }
  .box {
    width: 100%;
    height: 188px;
    position: relative;
    img {
      width: 100%;
      height: 100%;
    }
    .detail {
      width: 100%;
      height: 100%;
      padding: 0 48px;
      box-sizing: border-box;
      position: absolute;
      top: 0;
      left: 0;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      .left {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        span:first-child {
          font-size: 28px;
          color: #222222;
        }
        span:nth-child(2) {
          font-size: 60px;
          font-weight: 600;
          color: #222222;
        }
      }
      .right {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
        span:first-child {
          font-size: 28px;
          color: #222222;
          line-height: 40px;
        }
        span:nth-child(2) {
          font-size: 22px;
          color: #999999;
          margin-top: 10px;
        }
      }
    }
  }

  .van-button--plain.van-button--primary {
    width: 310px;
    height: 88px;
    background: #3f87f0;
    border-radius: 44px;
    font-size: 30px;
    font-weight: 500;
    color: #ffffff;
  }
  .van-col {
    font-size: 60px;
    color: #ffffff;
    margin-top: 86px;
  }
}

.convert{
  display: flex;
  flex-direction: row;
  justify-content: center;
  width: 100%;
  font-size: 30px;
  color: #E1E1E1;
  margin-top: 30px;
  text-decoration: underline ;
}
</style>
